package com.olymtech.jbricks.threadpool.config;

import com.olymtech.jbricks.threadpool.enums.QueueTypeEnum;
import com.olymtech.jbricks.threadpool.enums.RejectedExecutionHandlerEnum;
import lombok.Data;

import java.util.concurrent.TimeUnit;

/**
 * @author haoting.wang
 * @date 2020/10/14 2:46 下午
 **/
@Data
public class ThreadPoolProperties {

    private String threadPoolName = "JBricksThreadPool";

    /**
     * 核心线程数
     */
    private int corePoolSize = 1;

    /**
     * 最大线程数, 默认值为CPU核心数量
     */
    private int maximumPoolSize = Runtime.getRuntime().availableProcessors();

    /**
     * 空闲线程存活时间
     */
    private long keepAliveTime;

    /**
     * 空闲线程存活时间单位
     */
    private TimeUnit unit = TimeUnit.MILLISECONDS;

    /**
     * 队列类型
     */
    private String queueType = QueueTypeEnum.LINKED_BLOCKING_QUEUE.getType();

    /**
     * 拒绝策略
     */
    private String rejectedExecutionType = RejectedExecutionHandlerEnum.ABORT_POLICY.getType();

    /**
     * 队列容量
     */
    private int queueCapacity = Integer.MAX_VALUE;
    /**
     * 队列容量阀值，超过此值告警
     */
    private int queueCapacityThreshold = queueCapacity;

    @Override
    public String toString() {
        return "\n" +
                "threadPoolName:'" + threadPoolName + "\n" +
                "corePoolSize=" + corePoolSize + "\n" +
                "maximumPoolSize=" + maximumPoolSize + "\n" +
                "keepAliveTime=" + keepAliveTime + "\n" +
                "unit=" + unit + "\n" +
                "queueType='" + queueType + "\n" +
                "rejectedExecutionType='" + rejectedExecutionType + "\n" +
                "queueCapacity=" + queueCapacity + "\n" +
                "queueCapacityThreshold=" + queueCapacityThreshold + "\n";
    }
}
